package com.speedchina.permission.web.message;
import com.speedchina.common.message.email.entity.Mail;
import com.speedchina.common.message.email.service.MailService;
import com.speedchina.common.message.entity.Alert;
import com.speedchina.common.message.entity.SendStyle;
import com.speedchina.common.message.service.AlertService;
import com.speedchina.common.message.util.SendResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.thymeleaf.TemplateEngine;
import org.thymeleaf.context.Context;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
/**
 * @author zyw test
 */
@RestController
public class EmaiController {

    @Autowired
    MailService mailService;
    @Autowired
    AlertService alertService;
    @Autowired
    private TemplateEngine templateEngine;
    String to="1013910434@qq.com";
    String[] tos={"1013910434@qq.com","zhangyouwen2021@126.com"};
    String[] cc = {"1013910434@qq.com","zhangyouwen2021@126.com"};
    @RequestMapping("/sendSimpleMail")
    public SendResult sendSimpleMail(){
        SendResult sendResult = mailService.sendSimpleMail(to,"zhangyouwen2021@126.com", "测试简单邮件发送", "我是邮件内容");
        return sendResult;
    }
//    @RequestMapping("/sendSimpleMail2")
//    public SendResult sendSimpleMail2(){
//        SendResult sendResult = mailService.sendSimpleMail(tos,null,"发送两个收件人","发送两个收件人");
//        return sendResult;
//    }
//    @RequestMapping("/sendSimpleMail3")
//    public SendResult sendSimpleMail3(){
//        SendResult sendResult = mailService.sendSimpleMail(tos,cc,"发送两个收件人","发送两个收件人");
//        return sendResult;
//    }
    @RequestMapping("/sendSimpleMail1")
    public SendResult sendSimpleMail1(){
        String content = "<html>\n" +
                "\t<head>\n" +
                "\t\t<meta charset=\"utf-8\">\n" +
                "\t\t<title></title>\n" +
                "\t</head>\n" +
                "\t<body>\n" +
                "        <div style=\"display: flex;border: 1px brown solid; padding: 40px;\">\n" +
                "            <div style=\"border: 1px chocolate solid;margin-right: 10em;\">\n" +
                "                 <p style=\"color: red;text-align: center;\">我在测试html发送邮件效果</p>\n" +
                "                 <span style=\"color: gray;text-align: center;display: block;\">成功测试</span>\n" +
                "             </div>\n" +
                "            <div style=\"border: 1px chocolate solid;\">\n" +
                "                <p style=\"color: red;text-align: center;\">我在测试html发送邮件效果</p>\n" +
                "                <span style=\"color: gray;text-align: center;display: block;\">成功测试</span>\n" +
                "            </div>   \n" +
                "        </div>\n" +
                "\n" +
                "\t</body>\n" +
                "</html>";
        SendResult sendResult = mailService.sendHtmlMail(to,"测试HTML邮件发送",content);
        return sendResult;
    }

    @RequestMapping("/sendSimpleMail4")
    public SendResult sendSimpleMail4(){
        String filePath = "http://10.5.42.13:9080/resource/flightData/previewFlightFile?hdfsFilename=09E89721FB7441E994BC3BA703FD157E.JPG";
        SendResult sendResult = mailService.sendAttachmentsMail(to,"附件测试","附件测试",filePath);
        return sendResult;
    }
    @RequestMapping("/sendSimpleMail5")
    public SendResult sendSimpleMail5(){

        String[] FI = {"http://10.5.42.13:9080/resource/flightData/previewFlightFile?hdfsFilename=09E89721FB7441E994BC3BA703FD157E.JPG",
                "http://10.5.42.13:9080/resource/flightData/previewFlightFile?hdfsFilename=F663470AAFF048B7B30AFD62769796E0.JPG"};
        SendResult sendResult = mailService.sendAttachmentsMail(to,"附件测试","附件测试",FI);
        return sendResult;
    }
    @RequestMapping("/sendSimpleMail6")
    public SendResult sendSimpleMail6(){
        Context context = new Context();
        context.setVariable("name","zyw");
        context.setVariable("date","2021-05-13");
        context.setVariable("place","南京");
        Mail mail = new Mail();
        mail.setTo(tos);
        mail.setSubject("邮件测试");
        SendResult sendResult =   mailService.sendThymeleafFormwork("loginTemplate",context,mail);
        return sendResult;
    }
    @RequestMapping("/get")
    public  void get(){
//        Alert alert = new Alert();
//        alert.setContent("内容");
//        alert.setApplication("应用");
//        alert.setTitle("主题");
//        alertService.sendAlert("内容",null);
        System.out.println(1/0);
    }
}
